<?php

// [ 获取PK10开奖结果分页列表 ]
// GET pk10.volist
// http://sg.51hub.cn/api?pk10.volist
// http://sg.io/api?pk10.volist

namespace app\api\resource\pk10;
use think\facade\Validate;
use app\api\lib\Page;

class Volist
{
    // 方法
    public $_method = ['GET'];
    // 前置
    public $_pre    = ['member'];
    // 描述
    public $_description = '获取PK10开奖结果分页列表';
    // 参数
    public $_param  = [
        'page' => '请求页',
        'show' => '每页记录数量',
        'no'   => '期号,可选（后台调用时作查询条件）',
        'date' => '日期,可选（后台调用时作查询条件）',
    ];

    public function run(&$request)
    {
        $page  = $request->get('page/d',1);
        $show  = $request->get('show/d',10);
        $no    = $request->param('no/d',0);
        $date  = $request->param('date/s','','trim');

        $table = 'pk10';
        $where = '';
        if ( !empty($no) ) {
            if ( !Validate::regex($no,'/^\d{6}$/') ) return [422,'期号格式不正确'];
            $where[] = ['no','=',$no];
        }
        if ( !empty($date) ) {
            if ( !Validate::dateFormat($date,'Y-m-d') ) return [422,'日期格式不正确'];
            $sDate   = strtotime($date . ' 00:00:00');
            $eDate   = strtotime($date . ' 23:59:59');
            $where[] = ['create_time','>',$sDate];
            $where[] = ['create_time','<',$eDate];
        }
        $order = 'no DESC';
        $pagelist = Page::run($table,$where,$order,$page,$show);

        return [200,$pagelist];
    }
}
